const React = require('react');
const {View, StyleSheet} = require('react-native');
const {
    JDDevice,
    JDText,
    JDRouter,
    JDTouchable,
    JDButton,
    JDAddress
} = require('@areslabs/jdreact-core-lib');
const {NavigationBar} = JDRouter;

class JDAddressExample extends React.Component {
    render() {
        return (
            <View style={styles.wrapper}>
                <NavigationBar Title="JDAddress"/>
            
                <JDButton 
                    onPress = {() =>{
                        JDAddress.getAddress()
                            .then((info)=>{alert(JSON.stringify(info))})
                            .catch((e)=>{alert(e)})
                        }
                    }>
                    {'获取详细地址和经纬度'}
                </JDButton>

                <JDButton 
                    style={{marginTop: JDDevice.getRpx(60)}}
                    onPress = {() =>{
                        JDAddress.updateAddress({
                            "provinceId":  "22",                              // 省ID
                            "cityId": "1930",                                 // 市ID
                            "countyId": "50947",                              // 县ID    
                            "townId" : "52199",                               // 镇ID
                            "provinceName": "四川",                            // 省名称
                            "cityName": "成都市",                              // 市名称
                            "countyName": "武侯区",                            // 县名称
                            "townName": "机投镇",                              // 镇名称
                            "fullAddress": "四川成都市武侯区机投镇XXX街道XX号",    //全地址
                            "addressId": "138537316",                         //详细地址id
                            "addressDetail": "XXX街道XX号",                    //详细地址
                            "longitude": "103.98293",                         //经度
                            "latitude": "30.64878",                            //纬度
                            "isUserAddress": true
                        }).then(()=>{
                            JDAddress.getAddress().then((info)=>
                                alert(JSON.stringify(info))
                            )
                        }).catch((e)=>{alert(e)})
                    }}>
                    {'修改详细地址和经纬度'}
                </JDButton>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    wrapper: {
        flex: 1,

    }
});
module.exports = JDAddressExample;